﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Synthesis;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace 测试窗体
{
    public class Class1
    {
        /// <summary>
        /// 播放对象
        /// </summary>
        private SpeechSynthesizer speech = new SpeechSynthesizer();

        public void speak()
        {
            string voicename = "";
            foreach (InstalledVoice voice in speech.GetInstalledVoices())
            {
                VoiceInfo vi = voice.VoiceInfo;
                if (vi.Culture.Name == "zh-CN" && vi.Gender == VoiceGender.Female)
                {
                    voicename = vi.Name;
                    break;
                }
            }

            speech = new SpeechSynthesizer();

            speech.Rate = 0;
            speech.SelectVoice(voicename);//设置播音员（中文）
            //speech.SelectVoice("Microsoft Anna"); //英文
            speech.Volume = 100;
            //speech.SpeakAsync("左上脱靶");//语音阅读方法
            try
            {
                speech.Speak("左上脱靶");
            }
            catch (Exception)
            {

            }
        }

        [DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)]

        public static extern uint waveOutGetVolume(IntPtr hwo, uint dwVolume);


        [DllImport("user32.dll")]
        public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

        private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
        private const int APPCOMMAND_VOLUME_UP = 0x0a0000;
        private const int APPCOMMAND_VOLUME_DOWN = 0x090000;
        private const int WM_APPCOMMAND = 0x319;


        public void getvolue()
        {
            for (int i = 0; i < 5; ++i)
            {
                //uint a= waveOutGetVolume(IntPtr.Zero, 0x0000);
                Process p = Process.GetCurrentProcess();
                SendMessage(p.Handle, WM_APPCOMMAND, p.Handle, (IntPtr)APPCOMMAND_VOLUME_DOWN);
            }
        }
    }
   
}
